<?php
	$sanpham = new sanphambs();
	
	$dssanpham = $sanpham->GetList_New();
	
	// Lấy tổng số dòng
	$tongsodong = count($dssanpham);
	
	if(!isset($_GET['start']))
		$start = 0;
	else
		$start = $_GET['start'];
	
	$limit = 5;
	$next = $start + $limit;
	$back = $start - $limit;
	$danhsach = $sanpham->GetPageList_New($start, $limit);
?>
<h3>Sản phẩm mới nhất</h3>
<?php
	for($i = 0; $i < ($danhsach == false ? 0 : count($danhsach)) ; $i++)
	{
		if($danhsach[$i]['SoLuong']>0)
		{
			echo "<div id='SanPham'>";
				$hinhanh = new hinhanhbs();
				$hinhanh->MaSanPham = $danhsach[$i]['MaSanPham'];
				$dshinh = $hinhanh->GetList();
				echo "<a href='index.php?do=chitietsanpham&msp={$danhsach[$i]['MaSanPham']}'><img src='{$dshinh[0]['patch']}' /> </a>";
				echo "<p>
					<span class='GiaBan'>" . number_format($danhsach[$i]['DonGia']) . " VNĐ</span> 
					<span class='LuotXem'>" . $danhsach[$i]['LuotXem'] . " lượt xem</span>
				</p> ";
				echo "<p class='TenSanPham'>{$danhsach[$i]['TenSanPham']}</p>";
			echo "</div>";
		}
	}
?>
<?php
		if($tongsodong > $limit)
		{
			echo "<div id='PhanTrang' align = 'center'>";
				if($start > 0)
					echo "<a href='home_0&start=$back'>Trang trước</a>&nbsp;";
				
				$j = 1;
				for($i = 0; $i < $tongsodong; $i += $limit)
				{
					if($i == $start)
						echo "<span style='color:#ff0000;font-weight:bold;'>" . $j . "</span>&nbsp;";
					else
						echo "<a href='home_0&start=$i'>" . $j . "</a>&nbsp;";
					
					$j++;
				}
				
				if($start + $limit < $tongsodong)
					echo "<a href='home_0&start=$next'>Trang sau</a>";
			echo "</div>";
			echo "<br/>";
		}
?>
